golang byte to string

229

go string to byte array -

b := []byte("ABC€")
s := string([]byte{65, 66, 67, 226, 130, 172})

golang byte to string -

str:=string(data)
fmt.Print(str)

golang []byte to string -

s := string([]byte{65, 66, 67, 226, 130, 172})
fmt.Println(s) // ABC€

golang convert string to bytes and convert bytes to string -

package main
 
import (
    "fmt"
)
 
func main() {
    var s string = "Hello World"
    sb := []byte(s)
     
    fmt.Println(sb)  // [72 101 108 108 111 32 87 111 114 108 100]
     
    fmt.Println(string(sb)) // Hello World
}

Comments

Submit
0 Comments